package scriptlerweb

class RenderUtil {
	
	static String render(def request, String obj, String field){
		def str = request.getAttribute(obj)?."$field"
		if(!str){
			str = ""
		}
		return str
	}
	
	
	static String shortenTo(int outputLength, String originOutput){
		if(originOutput && originOutput.length() > outputLength){
			def s = originOutput.substring(0, outputLength)
			return s +"..."
		}
		return originOutput ? originOutput : ''
	}
	
	
	static String fallback(String fallback, String origin){
		def s = origin ? origin : fallback
		s = s.equals('null') ? '' : s
		return s
	}
	
	static String removeHtml(String input){
//		return input.replaceAll("s/<[a-zA-Z\\/][^>]*>//g", '')
		println("befor: "+input)
		input = input.replaceAll("<(.|\n)*?>", '')
		println("after: "+input)
		return input
	}
}
